/**
 * 银行卡列表
 */
interface BankListItemResponse {
    /**
     * 标识符
     */
    id:string,
    /**
     * 序号
     */
    index:number,
    /**
     * 开户银行
     */
    bank:string,
    /**
     * 银行卡号
     */
    cardNumber:string,
    /**
     * 持卡人姓名
     */
    holder:string
}

/**
 *   帐户详情
 */
interface BankDetailResponse extends BaseResponse {
    /**
    * 标识符
    */
    id:string,
    /**
    * 序列号
    */
    index:number,
    /**
    * 开户银行
    */
    bank:string,
    /**
    * 银行卡号
    */
    cardNumber:string,
    /**
    * 持卡人姓名
    */
    holder:string
}


/**
 * 银行服务
 */
interface IBankService {
    /**
     * 获取银行卡信息
     * v1.0
     * @param id 银行卡号
     */
    getBankName(id: string): ng.IHttpPromise<string>;
    /**
     * 获取银行列表
     * v1.0
     * @param carId 车辆编号
     * @param carrierId 承运商编号
     * @param bankCode 银行卡号
     * @param isVehicle 是否是车场查询
     * @param skip 跳过项数
     * @param count 获取项数
     */
    getList(carid:string, carrierid:string,BankCode:string,IsVehicle:boolean,skip:number,count:number): ng.IHttpPromise<ListResponse<BankListItemResponse>>;
    /**
     * 获取帐户详情
     * v1.0
     * @param id 银行卡号
     */
    getDetail(id: string): ng.IHttpPromise<BankDetailResponse>;
    /**
     * 添加银行卡
     * v1.0
     * @param bank 开户银行
     * @param cardNumber 银行卡号
     * @param holder 持卡人姓名
     * @param carrierId 承运商编号
     * @param carId 车辆编号
     */
    add(bank:string,cardNumber:string,holder:string,carrierId:string,carId:string): ng.IHttpPromise<BaseResponse>;
    /**
     * 删除银行卡
     * v1.0
     * @param id 银行卡号
     * @param vehicleId 车辆编号
     * @param carrierId 承运商编号
     */
    delete(id: string,VehicleID:string,CarrierID:string): ng.IHttpPromise<BaseResponse>;
}

class bankService implements IBankService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    getBankName(id: string): ng.IHttpPromise<string> {
        return this.http<string>({
            method: "GET",
            url: this.route.getUrl("bank/GetBankName?id={{id}}", {
                   id:id
                })
        });
    }

    getList(carid:string, carrierid:string,BankCode:string,IsVehicle:boolean,skip:number,count:number): ng.IHttpPromise<ListResponse<BankListItemResponse>> {
        return this.http<ListResponse<BankListItemResponse>>({
            method: "GET",
            url: this.route.getUrl("bank?carid={{carid}}&carrierid={{carrierid}}&BankCode={{BankCode}}&IsVehicle={{IsVehicle}}&skip={{skip}}&count={{count}}",{
                    carid: carid,
                    carrierid: carrierid,
                    BankCode: BankCode,
                    IsVehicle: IsVehicle,
                    skip: skip,
                    count: count
                })
        });
    }

    getDetail(id: string): ng.IHttpPromise<BankDetailResponse> {
        return this.http<BankDetailResponse>({
            method: "GET",
            url: this.route.getUrl("bank/{{id}}", {
                id: id
            })
        });
    }

    add(bank:string,cardNumber:string,holder:string,carrierId:string,carId:string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "POST",
            url: this.route.getUrl("bank"),
            data: {
                bank: bank,
                cardNumber: cardNumber,
                holder:holder,
                carrierId:carrierId,
                carId:carId   
            }
        });
    }

    delete(id:string,VehicleID:string,CarrierID:string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "DELETE",
            url: this.route.getUrl("bank/{{id}}?VehicleID={{VehicleID}}&CarrierID={{CarrierID}}", {
                id: id,
                VehicleID:VehicleID,
                CarrierID:CarrierID
            })
        });
    }
}

angular.module("bankService",[]).service("bankService",['$http','routeService',bankService]);